{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.连接\n",
    "\n",
    "- np.hstack()\n",
    "- np.vstack()\n",
    "- np.column_stack() :把一维数组堆成多维数据\n",
    "- np.row_stack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "np.hstack(): \n",
      " [[ 0  1  2  3  4  0  1  2  3  4]\n",
      " [ 5  6  7  8  9  5  6  7  8  9]\n",
      " [10 11 12 13 14 10 11 12 13 14]]\n",
      "np.vstack(): \n",
      " [[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]\n",
      " [ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n",
      "np.column_stack(): \n",
      " [[ 0  6]\n",
      " [ 1  7]\n",
      " [ 2  8]\n",
      " [ 3  9]\n",
      " [ 4 10]]\n",
      "np.row_stack(): \n",
      " [[ 0  1  2  3  4]\n",
      " [ 6  7  8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(0, 15).reshape(3, 5)\n",
    "b = np.arange(0, 15).reshape(3, 5)\n",
    "\n",
    "print(\"np.hstack(): \\n\", np.hstack((a, b)))\n",
    "print(\"np.vstack(): \\n\", np.vstack((a, b)))\n",
    "\n",
    "c = np.arange(0, 5)\n",
    "d = np.arange(6, 11)\n",
    "print(\"np.column_stack(): \\n\", np.column_stack((c, d)))\n",
    "print(\"np.row_stack(): \\n\", np.row_stack((c, d)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.切分\n",
    "\n",
    "- hsplit()\n",
    "- vsplit()\n",
    "- split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a.shape: \n",
      " (6, 6)\n",
      "\n",
      "a1.shape: \n",
      " (6, 3)\n",
      "a2.shape: \n",
      " (6, 3)\n",
      "\n",
      "a1.shape: \n",
      " (6, 1)\n",
      "a2.shape: \n",
      " (6, 3)\n",
      "a3.shape: \n",
      " (6, 2)\n",
      "\n",
      "a1.shape: \n",
      " (2, 1, 2)\n",
      "\n",
      "a2.shape: \n",
      " (2, 1, 2)\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(36).reshape(6, 6)\n",
    "print(\"a.shape: \\n\", a.shape)\n",
    "\n",
    "a1, a2 = np.hsplit(a, 2)\n",
    "print(\"\\na1.shape: \\n\", a1.shape)\n",
    "print(\"a2.shape: \\n\", a2.shape)\n",
    "\n",
    "a1, a2, a3 = np.hsplit(a, [1, 4])\n",
    "print(\"\\na1.shape: \\n\", a1.shape)\n",
    "print(\"a2.shape: \\n\", a2.shape)\n",
    "print(\"a3.shape: \\n\", a3.shape)\n",
    "\n",
    "a = np.arange(8.0).reshape(2, 2, 2)\n",
    "a1, a2 = np.hsplit(a, 2) # 默认axis=1\n",
    "print(\"\\na1.shape: \\n\", a1.shape)\n",
    "print(\"\\na2.shape: \\n\", a2.shape)\n",
    "\n",
    "# vsplit的用法与hsplit一样\n",
    "# split用法与hsplit的用法一样，需要执行轴"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
